home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / KDChartTableBase.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-05-30  |  16.3 KB  |  479 lines

  1. /* -*- Mode: C++ -*-
  2.    KDChart - a multi-platform charting engine
  3. */
  4.  
  5. /****************************************************************************
  6.  ** Copyright (C) 2001-2003 Klar├ñlvdalens Datakonsult AB.  All rights reserved.
  7.  **
  8.  ** This file is part of the KDChart library.
  9.  **
  10.  ** This file may be distributed and/or modified under the terms of the
  11.  ** GNU General Public License version 2 as published by the Free Software
  12.  ** Foundation and appearing in the file LICENSE.GPL included in the
  13.  ** packaging of this file.
  14.  **
  15.  ** Licensees holding valid commercial KDChart licenses may use this file in
  16.  ** accordance with the KDChart Commercial License Agreement provided with
  17.  ** the Software.
  18.  **
  19.  ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  20.  ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  21.  **
  22.  ** See http://www.klaralvdalens-datakonsult.se/?page=products for
  23.  **   information about KDChart Commercial License Agreements.
  24.  **
  25.  ** Contact info@klaralvdalens-datakonsult.se if any conditions of this
  26.  ** licensing are not clear to you.
  27.  **
  28.  **********************************************************************/
  29. #ifndef __KDCHARTTABLEINTERFACE_H__
  30. #define __KDCHARTTABLEINTERFACE_H__
  31.  
  32.  
  33. class QTable;
  34.  
  35. #include <qvariant.h>
  36. #include <qobject.h>
  37. #include <qdatetime.h>
  38.  
  39. #include <kdchart_export.h>
  40.  
  41. #if defined( SUN7 ) || defined (_SGIAPI)
  42.   #include <float.h>
  43.   #include <limits.h>
  44. #else
  45.   #include <cfloat>
  46.   #include <climits>
  47. #endif
  48.  
  49.  
  50. /**
  51.     Use special value KDCHART_POS_INFINITE to indicate positive infinite values.
  52.  
  53.     If your own table class (derived from KDChartTableDataBase) does
  54.     not store your positive infinite values as KDCHART_POS_INFINITE
  55.     please make sure to reimplement \sa isPosInfinite() accordingly.
  56.  
  57.     \sa isPosInfinite, isNegInfinite
  58. */
  59. #define KDCHART_POS_INFINITE DBL_MAX
  60.  
  61. /**
  62.     Use special value KDCHART_NEG_INFINITE to indicate negative infinite values.
  63.  
  64.     If your own table class (derived from KDChartTableDataBase) does
  65.     not store your negative infinite values as KDCHART_NEG_INFINITE
  66.     please make sure to reimplement \sa isNegInfinite() accordingly.
  67.  
  68.     \sa isNegInfinite, isPosInfinite
  69. */
  70. #define KDCHART_NEG_INFINITE -DBL_MAX
  71.  
  72.  
  73. /**
  74.    \file KDChartTableBase.h
  75.  
  76.    \brief Provides a table class holding all data values
  77.    that are to be used in a chart.
  78.  
  79.    By subclassing KDChartTableDataBase you may provide your own
  80.    methods to access data stored somewhere else instead of
  81.    using the setCell function to move them into KD Chart's cells.
  82.  
  83.    \note See the files in doc/tutorial/step07/ for a sample implementation you might want to use as starting-point for your own data handling class.
  84. */
  85.  
  86. ///KD Chart's build-in table data for an easy way of storing data values.
  87. class KDCHART_EXPORT KDChartTableDataBase :public QObject
  88. {
  89.     Q_OBJECT
  90. public:
  91.     /**
  92.       Default constructor.
  93.  
  94.       Creates an empty table and sets the sorted flag to false.
  95.       */
  96.     KDChartTableDataBase() :
  97.         QObject( 0 ),
  98.         _sorted(false),
  99.         _useUsedRows(false),
  100.         _useUsedCols(false) {}
  101.     /**
  102.       Default copy constructor.
  103.  
  104.       Just initializes the QObject part of this class and copies the sorted flag.
  105.       */
  106.     KDChartTableDataBase( const KDChartTableDataBase& other ) :QObject(0)
  107.     {
  108.         _sorted      = other._sorted;
  109.         _useUsedRows = other._useUsedRows;
  110.         _useUsedCols = other._useUsedCols;
  111.         _usedRows    = other._usedRows;
  112.         _usedCols    = other._usedCols;
  113.     }
  114.     /**
  115.       Default destructor.
  116.  
  117.       Does nothing, only defined to have it virtual.
  118.       */
  119.     virtual ~KDChartTableDataBase() {}
  120.  
  121. public slots:
  122.     /**
  123.       Returns the number of rows in the table.
  124.  
  125.       \note This pure-virtual function has to be implemented by
  126.       each class derived from KDChartTableDataBase.
  127.  
  128.       \returns the number of rows in the table.
  129.  
  130.       \sa setRows, usedRows, cols
  131.       */
  132.     virtual uint rows() const = 0;
  133.     /**
  134.       Returns the number of cols in the table.
  135.  
  136.       \note This pure-virtual function has to be implemented by
  137.       each class derived from KDChartTableDataBase.
  138.  
  139.       \returns the number of cols in the table.
  140.  
  141.       \sa setCols, usedCols, rows
  142.       */
  143.     virtual uint cols() const = 0;
  144.  
  145.     /**
  146.       Stores data in a cell.
  147.  
  148.       \note This pure-virtual function has to be implemented by
  149.       each class derived from KDChartTableDataBase.
  150.  
  151.       \param _row the row number of the cell to store the data object into.
  152.       \param _col the column number of the cell to store the data object into.
  153.       \param _value1 the first value to be stored, normally the Y value, possible types: int, double, QString
  154.       QString might be used in case you want to use this cell's content for axis label
  155.       \param _value2 the second value to be stored, normally the X value (if any), possible types: int, double, QDateTime
  156.  
  157.       \sa cellCoords, cellContent, setProp
  158.       */
  159.     virtual void setCell( uint _row, uint _col,
  160.                           const QVariant& _value1,
  161.                           const QVariant& _value2=QVariant() ) = 0;
  162.     /**
  163.       Specifies the property set ID for a cell.
  164.  
  165.       \note This pure-virtual function has to be implemented by
  166.       each class derived from KDChartTableDataBase.
  167.     
  168.       \param _row the row number of the cell.
  169.       \param _col the column number of the cell.
  170.       \param _propSet the property set ID to be stored for this data cell, defaults to zero for normal data.
  171.     
  172.       \sa cellProp, cellContent, setCell
  173.       */
  174.     virtual void setProp( uint _row, uint _col,
  175.                           int _propSet=0 ) = 0;
  176.  
  177.     /**
  178.       Returns one of the coordinate data value(s) stored in a cell.
  179.  
  180.       \note This pure-virtual function has to be implemented by
  181.       each class derived from KDChartTableDataBase.
  182.  
  183.       \param _row the row number of the cell to be retrieved.
  184.       \param _col the column number of the cell to be retrieved.
  185.       \param _value the coordinate variable to be filled by this method.
  186.       \param coordinate the number of the coordinate to be retrieved, normally
  187.       1 is the Y value and 2 is the X value.
  188.  
  189.       \returns TRUE if the row and col are addressing a cell in the table.
  190.  
  191.       \sa cellCoords, cellProp, cellContent, cellVal, setCell, setProp
  192.       */
  193.     virtual bool cellCoord( uint _row, uint _col,
  194.                             QVariant& _value,
  195.                             int coordinate=1 ) const = 0;
  196.  
  197.     /**
  198.       Returns one of the coordinate data value(s) stored in a cell.
  199.  
  200.       This convenience method calls the bool cellCoord() function and returns
  201.       the result if it returned successfully - otherwise it returns an invalid QVariant.
  202.  
  203.       \note If you \em know that a cell is containing valid double data
  204.       you may quickly access them like this:
  205. \verbatim const double yVal = data.cellVal( r, c    ).toDouble();
  206. const double xVal = data.cellVal( r, c, 2 ).toDouble(); \endverbatim
  207.  
  208.       \param _row the row number of the cell to be retrieved.
  209.       \param _col the column number of the cell to be retrieved.
  210.       \param coordinate the number of the coordinate to be retrieved, normally
  211.       1 is the Y value and 2 is the X value.
  212.  
  213.       \returns cell contens if the row and col are addressing a cell in the
  214.       table, otherwise an invalid QVariant is returned.
  215.  
  216.       \sa cellCoords, cellProp, cellContent, setCell, setProp
  217.       */
  218.     virtual QVariant cellVal( uint _row, uint _col, int coordinate=1 ) const {
  219.         QVariant value;
  220.         if( cellCoord( _row, _col, value, coordinate ) )
  221.             return value;
  222.         else
  223.             return QVariant();
  224.     }
  225.  
  226.     /**
  227.       Returns the property set ID stored in a cell.
  228.  
  229.       \note This pure-virtual function has to be implemented by
  230.       each class derived from KDChartTableDataBase.
  231.  
  232.       \param _prop the property set ID of the cell to be retrieved.
  233.  
  234.       \returns TRUE if the row and col are addressing a cell in the table.
  235.  
  236.       \sa cellCoord, cellCoords, cellContent, setCell, setProp
  237.       */
  238.     virtual bool cellProp( uint _row, uint _col,
  239.                            int& _prop ) const = 0;
  240.  
  241.     /**
  242.       Increases the number of rows (and/or columns, resp.) stored in this table.
  243.  
  244.       \note This pure-virtual function has to be implemented by
  245.       each class derived from KDChartTableDataBase.
  246.  
  247.       \note The old content of the table must be preserved (e.g. by copying
  248.       the data into the cells of the new table).
  249.  
  250.       \param _row the new number of rows.
  251.       \param _col the new number of columns.
  252.  
  253.       \sa cell
  254.       */
  255.     virtual void expand( uint _rows, uint _cols ) = 0;
  256.  
  257.  
  258.  
  259.     //  E N D   O F   pure-virtual function declarations
  260.  
  261.  
  262.  
  263.     /**
  264.       \note To improve runtime speed this virtual function
  265.       may be reimplemented by classes derived from KDChartTableDataBase.
  266.  
  267.       \sa cellCoords, cellProp, setCell, setProp
  268.       */
  269.     virtual bool cellContent( uint _row, uint _col,
  270.                               QVariant& _value1,
  271.                               QVariant& _value2,
  272.                               int&      _prop ) const
  273.     {
  274.         return cellCoords(_row,_col, _value1,_value2) &&
  275.                cellProp(_row,_col, _prop);
  276.     }
  277.     /**
  278.       \note To improve runtime speed this virtual function
  279.       may be reimplemented by classes derived from KDChartTableDataBase.
  280.  
  281.       \sa cellCoord, cellProp, cellContent, setCell, setProp
  282.       */
  283.     virtual bool cellCoords( uint _row, uint _col,
  284.                              QVariant& _value1,
  285.                              QVariant& _value2 ) const
  286.     {
  287.         return cellCoord(_row,_col, _value1, 1) &&
  288.                cellCoord(_row,_col, _value2, 2);
  289.     }
  290.  
  291.  
  292.     /**
  293.       Sets the number of rows in the table that actually contain data.
  294.  
  295.       \note You might want to re-implement this function in derived classes,
  296.       the default implementation just stores the new number of used rows.
  297.  
  298.       \param _rows the number of rows in the table that actually contain data.
  299.     
  300.       \sa usedRows, rows, cols
  301.       */
  302.     virtual void setUsedRows( uint _rows );
  303.     /**
  304.       Returns the number of rows in the table that actually contain data.
  305.     
  306.       \returns the number of rows in the table that actually contain data.
  307.  
  308.       \sa setUsedRows, rows, cols
  309.       */
  310.     virtual uint usedRows() const;
  311.  
  312.     /**
  313.       Sets the number of cols in the table that actually contain data.
  314.  
  315.       \note You might want to re-implement this function in derived classes,
  316.       the default implementation just stores the new number of used cols.
  317.  
  318.       \param _cols the number of cols in the table that actually contain data.
  319.  
  320.       \sa usedCols, rows, cols
  321.       */
  322.     virtual void setUsedCols( uint _cols );
  323.     /**
  324.       Returns the number of cols in the table that actually contain data.
  325.  
  326.       \returns the number of cols in the table that actually contain data.
  327.  
  328.       \sa setUsedCols, rows, cols
  329.       */
  330.     virtual uint usedCols() const;
  331.  
  332.  
  333.     /**
  334.       Returns the number of cols the table has been scrolled by.
  335.  
  336.       Default implementation of this always returns zero, so make sure
  337.       to return the appropriate value if your class derived from KDChartTableDataBase
  338.       is supporting internal data scrolling technics.
  339.  
  340.       See the KD Chart Programmers Manual for details described in the
  341.       Data Scrolling chapter.
  342.  
  343.       \returns the number of cols the table has been scrolled by.
  344.  
  345.       \sa cols, rows
  346.       */
  347.     virtual uint colsScrolledBy() const
  348.     {
  349.         return 0;
  350.     }
  351.  
  352.  
  353.     /**
  354.       Specified whether the table is sorted.
  355.  
  356.       \sa sorted
  357.     */
  358.     virtual void setSorted(bool sorted);
  359.     /**
  360.       Returns whether the table is sorted.
  361.  
  362.       \sa setSorted
  363.     */
  364.     virtual bool sorted() const;
  365.     
  366.     /**
  367.         Returns true if the given value represents a positive infinite value.
  368.         
  369.         \note This virtual function may be implemented by
  370.         classes derived from KDChartTableDataBase.
  371.         This should be done if your data are not stored as
  372.         special value KDCHART_POS_INFINITE
  373.         to indicate positive infinite values
  374.  
  375.         \returns TRUE if the value given is a positive infinite value.
  376.     */
  377.     virtual bool isPosInfinite( double value ) const
  378.     {
  379.         return value == KDCHART_POS_INFINITE;
  380.     }
  381.     
  382.     /**
  383.         Returns true if the given value represents a negative infinite value.
  384.         
  385.         \note This virtual function may be implemented by
  386.         classes derived from KDChartTableDataBase.
  387.         This should be done if your data are not stored as
  388.         special value KDCHART_NEG_INFINITE
  389.         to indicate negative infinite values
  390.         
  391.         \returns TRUE if the value given is a negative infinite value.
  392.     */
  393.     virtual bool isNegInfinite( double value ) const
  394.     {
  395.         return value == KDCHART_NEG_INFINITE;
  396.     }
  397.  
  398.     /**
  399.         Returns true if the given value represents a normal double value.
  400.  
  401.         Normal double values are defined as values that are neither positive infinite
  402.         nor negative infinite.  This method is provided to let derived classed use
  403.         their own way to determine when a double value is to be threated as normal.
  404.  
  405.         \note To improve runtime speed this virtual function
  406.         may be reimplemented by classes derived from KDChartTableDataBase.
  407.  
  408.         \returns TRUE if the value given is neither positive infinite nor negativr infinite.
  409.     */
  410.     virtual bool isNormalDouble( double value ) const
  411.     {
  412.         return !isPosInfinite( value ) && !isNegInfinite( value );
  413.     }
  414.  
  415.     /**
  416.         Returns true if the given QVariant value represents a normal double value.
  417.  
  418.         This method tests if \c value has type QVariant::Double: if no, it returns false;
  419.         if yes, it sets \c dVal accordingly and calls the virtual method
  420.         isNormalDouble( double value ).
  421.  
  422.         \param value The QVariant value to be tested and converted.
  423.         \param dVal Points to the double variable to be filled with the converted value.
  424.  
  425.         \returns TRUE if the value given is neither positive infinite nor negative
  426.         infinite, \c value is set to the converted value if the type of \c value
  427.         is QVariant::Double, otherwise it is not modified.
  428.     */
  429.     bool isNormalDouble( QVariant value, double& dVal ) const
  430.     {
  431.         if( QVariant::Double != value.type() )
  432.             return false;
  433.         dVal = value.toDouble();
  434.         return isNormalDouble( dVal );
  435.     }
  436.  
  437.     virtual void importFromQTable( QTable* table );
  438.  
  439.     virtual double maxValue( int coordinate=1 ) const;
  440.     virtual double minValue( int coordinate=1, bool bOnlyGTZero=false ) const;
  441.  
  442.     virtual QDateTime maxDtValue( int coordinate=1 ) const;
  443.     virtual QDateTime minDtValue( int coordinate=1 ) const;
  444.  
  445.     virtual double maxColSum( int coordinate=1 ) const;
  446.     virtual double minColSum( int coordinate=1 ) const;
  447.     virtual double maxColSum( uint row, uint row2, int coordinate=1 ) const;
  448.     virtual double minColSum( uint row, uint row2, int coordinate=1 ) const;
  449.     virtual double colSum( uint col, int coordinate=1 ) const;
  450.     virtual double colAbsSum( uint col, int coordinate=1 ) const;
  451.     virtual double maxRowSum( int coordinate=1 ) const;
  452.     virtual double minRowSum( int coordinate=1 ) const;
  453.     virtual double rowSum( uint row, int coordinate=1 ) const;
  454.     virtual double rowAbsSum( uint row, int coordinate=1 ) const;
  455.     virtual double maxInColumn( uint col, int coordinate=1 ) const;
  456.     virtual double minInColumn( uint col, int coordinate=1 ) const;
  457.     virtual double maxInRow( uint row, int coordinate=1 ) const;
  458.     virtual double minInRow( uint row, int coordinate=1 ) const;
  459.     virtual double maxInRows( uint row, uint row2, int coordinate=1 ) const;
  460.     virtual double minInRows( uint row, uint row2, int coordinate=1, bool bOnlyGTZero=false ) const;
  461.     virtual QDateTime maxDtInRows( uint row, uint row2, int coordinate=1 ) const;
  462.     virtual QDateTime minDtInRows( uint row, uint row2, int coordinate=1 ) const;
  463.     virtual uint lastPositiveCellInColumn( uint col, int coordinate=1 ) const;
  464.     virtual bool cellsHaveSeveralCoordinates(QVariant::Type* type2Ref) const;
  465.     virtual bool cellsHaveSeveralCoordinates(uint row1=0, uint row2=UINT_MAX,
  466.                                              QVariant::Type* type2Ref=NULL) const;
  467.     virtual QVariant::Type cellsValueType( uint row1, uint row2=UINT_MAX,
  468.                                            int coordinate=1 ) const;
  469.     virtual QVariant::Type cellsValueType( int coordinate=1 ) const;
  470. private:
  471.     bool _sorted;
  472. protected:
  473.     bool _useUsedRows, _useUsedCols;
  474. private:
  475.     uint _usedRows, _usedCols;
  476. };
  477.  
  478. #endif
  479.